//
//  AISetLogoutAlertView.m
//  Mia
//
//  Created by Vill on 2024/1/18.
//

#import "AISetLogoutAlertView.h"

@interface AISetLogoutAlertView ()

@property (nonatomic, strong) UIVisualEffectView *blurView; //模糊
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) UIButton *confirmBtn;   //确认
@property (nonatomic, strong) UILabel *alertTitle;    //标题
@property (nonatomic, strong) UILabel *detailLbl;     //详情

@end

@implementation AISetLogoutAlertView

- (instancetype)initWithType:(NSInteger)type{
    self = [super init];
    if (self) {
        self.contentView.backgroundColor = UIColor.clearColor;
        [self.contentView addSubview:self.blurView];
        [self.contentView addSubview:self.closeBtn];
        [self.contentView addSubview:self.confirmBtn];
        [self.contentView addSubview:self.alertTitle];
        
        [self.blurView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.top.mas_equalTo(self.contentView);
            if (type == 0){
                make.height.mas_equalTo(PTW(280));
            }else{
                make.height.mas_equalTo(PTW(245));
            }
            make.bottom.mas_equalTo(self.contentView);
        }];
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(PTW(34));
            make.top.mas_equalTo(self.contentView).mas_offset(PTW(15));
            make.trailing.mas_equalTo(self.contentView).mas_offset(-PTW(15));
        }];
        [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.contentView).mas_offset(PTW(15));
            make.trailing.mas_equalTo(self.contentView).mas_offset(-PTW(15));
            make.bottom.mas_equalTo(self.contentView).mas_offset(-PTW(30));
            make.height.mas_equalTo(PTW(60));
        }];
        
        // type 0 delete  1 logout
        if (type == 0){
            [self.alertTitle mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.contentView).mas_offset(PTW(20));
                make.centerX.mas_equalTo(self.contentView);
            }];
            [self.contentView addSubview:self.detailLbl];
            [self.detailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(self.contentView);
                make.top.mas_equalTo(self.alertTitle.mas_bottom).mas_offset(PTW(35));
            }];
            self.alertTitle.text = @"Are you sure to \ndelete your account?";
            self.detailLbl.text = @"After being deleted, data will \nbe permanently deleted";
        }else{
            [self.alertTitle mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(self.contentView);
                make.top.mas_equalTo(self.contentView).mas_offset(PTW(77));
            }];
            self.alertTitle.text = @"Are you sure to log out?";
        }
    }
    return self;
}

// 关闭
-(void)closeAction{
    [self dismiss];
}

// 确认
-(void)confirmAction{
    [self dismiss];
    if (self.confirmBlock){
        self.confirmBlock();
    }
}

- (UIVisualEffectView *)blurView{
    if(!_blurView){
        UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        _blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        _blurView.alpha = 0.9;
        _blurView.backgroundColor = [UIColor colorHex:@"#FFFFFF" alpha:0.2];
    }
    return _blurView;
}

-(UIButton *)closeBtn{
    if(!_closeBtn){
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:KImaged(@"ai_main_close") forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}

- (UIButton *)confirmBtn{
    if(!_confirmBtn){
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setTitle:@"Confirm" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:[UIColor colorHex:@"#5C5C5C"] forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = [UIFont fontWithWeight:MTBold size:PTW(15)];
        _confirmBtn.backgroundColor = [UIColor whiteColor];
        _confirmBtn.layer.cornerRadius = PTW(30);
        _confirmBtn.layer.shadowColor = [UIColor colorHex:@"#FFFFFF" alpha:0.68].CGColor;
        _confirmBtn.layer.shadowOffset = CGSizeMake(0,0);
        _confirmBtn.layer.shadowOpacity = 1;
        _confirmBtn.layer.shadowRadius = 8;
        [_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

- (UILabel *)alertTitle{
    if(!_alertTitle){
        _alertTitle = [UILabel new];
        _alertTitle.textColor = [UIColor whiteColor];
        _alertTitle.font = [UIFont fontWithWeight:MTBold size:PTW(22)];
        _alertTitle.textAlignment = NSTextAlignmentCenter;
        _alertTitle.numberOfLines = 0;
    }
    return _alertTitle;
}

- (UILabel *)detailLbl{
    if(!_detailLbl){
        _detailLbl = [UILabel new];
        _detailLbl.textColor = [UIColor whiteColor];
        _detailLbl.font = [UIFont fontWithWeight:Regular size:PTW(18)];
        _detailLbl.textAlignment = NSTextAlignmentCenter;
        _detailLbl.numberOfLines = 0;
    }
    return _detailLbl;
}

@end
